package sistemioperativi.barbiere.es12;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Barbiere implements Runnable{
	
	private Salone salone;
	
	public Barbiere(Salone salone){
		this.salone = salone;
	}
	
	public void run(){
		
		try{
			
			while(true){
				salone.getCliente();
				tagliaCapelli();
				salone.congedaCliente();
			}
			
		}catch(InterruptedException e){
			//NOOP
		}
	}
	
		
		private void tagliaCapelli() throws InterruptedException{
			attendi(8,3);
		}
		protected static void attendi(int min, int max) throws InterruptedException{ 
			Random random = new Random();	
			TimeUnit.SECONDS.sleep(random.nextInt(max - min + 1) + min);
		
		}
}
